package com.jt.consumer.service;

import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 远程服务回调工程
 * 当远程服务不可用时，可以通过此工厂创建一个service对象，返回一些友好信息
 * */
@Component
public class ProviderFallBackFactory implements FallbackFactory<RemoteProviderService> {
    @Override
    public RemoteProviderService create(Throwable throwable) {
        //构建匿名内部类
        /*远端服务不能访问时，给用户返回的信息*/
        /*return new RemoteProviderService() {
            @Override
            public String echoMessage(String msg) {
                return "服务忙，稍等片刻再访问";
            }
        };*/
        //JDK8中lambda表达式
        return (msg) -> {
            return "服务忙，稍等片刻再访问";
        };
    }
}
